package git.soulbgm;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.HashMap;

/**
 * @author SoulBGM
 * @version 1.0
 * @date 2019/11/9 23:27
 */
public class Demo {

    public static void main(String[] args) {
        String originUrlpath = "https://tudou.com-l-tudou.com/20190524/18931_19398088/1000k/hls/index.m3u8";
        String preUrlPath = originUrlpath.substring(0, originUrlpath.lastIndexOf("/")+1);
        String rootPath = "G:\\hy";
        String fileName = "";
        HlsDownloader downLoader = new HlsDownloader(originUrlpath, preUrlPath, rootPath);
        //downLoader.setThreadQuantity(10);
        try{
            fileName = downLoader.download(true);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if(fileName.isEmpty()){
            System.out.println("下载失败");
        }else{
            System.err.println("下载成功");
        }
    }

    /*public static void main(String[] args) throws Exception {
        String rootPath = "G:/hy/dcd88ab336aa4578880d2717eb820ed2";
        File file1 = new File(rootPath);
        File[] files = file1.listFiles();
        HashMap<Integer, String> keyFileMap = new HashMap<>();
        for (int i = 0; i < files.length; i++) {
            File f = files[i];
            String path = f.getPath();
            keyFileMap.put(i, path);
        }

        String fileOutPath = rootPath + File.separator + "all.mp4";
        FileOutputStream fileOutputStream = new FileOutputStream(new File(fileOutPath));
        byte[] bytes = new byte[1024];
        int length = 0;
        for (int i = 0; i < keyFileMap.size(); i++) {
            String nodePath = keyFileMap.get(i);
            File file = new File(nodePath);
            if (!file.exists()) {
                continue;
            }

            FileInputStream fis = new FileInputStream(file);
            while ((length = fis.read(bytes)) != -1) {
                fileOutputStream.write(bytes, 0, length);
            }
        }

        System.out.println(fileOutPath);

    }*/

}
